package yagwl.client.model.demo;

import java.util.List;
import java.util.logging.Logger;

import yagwl.client.model.FilterDTO;
import yagwl.client.model.FilteredItemListCache;
import yagwl.client.model.ItemDTO;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class FilteredLaureateCache extends FilteredItemListCache {

	private static Logger log = Logger.getLogger(FilteredLaureateCache.class.getName());
  private LaureateRpcServiceAsync laureateService = GWT.create(LaureateRpcService.class);

  @Override
  public void fetchNext() {
    if (isLoadInProgress())
      return;
    loadStart();
    laureateService.getLaureates(getLoadStartIndex(), getLoadFetchSize(),
        getSortOrder(), selectedFilters, new AsyncCallback<List<ItemDTO>>() {
          @Override
          public void onFailure(Throwable caught) {
            onLoadFailure(caught);
          }

          @Override
          public void onSuccess(List<ItemDTO> result) {
            onLoadSuccess(result);
          }
        });
  }

  @Override
  public void fetchFilters() {
  	laureateService.getFilters(new AsyncCallback<List<FilterDTO>>() {

			@Override
      public void onFailure(Throwable caught) {
	      // TODO Auto-generated method stub	      
      }

			@Override
      public void onSuccess(List<FilterDTO> result) {
		    onLoadFiltersSuccess(result);
      }
  	});
  }

	@Override
  protected void onFilterSelection() {
    // in some circumstances, may not want to clear here, but may perform
    // client side filtering
    clearList();
  }

  @Override
  public void deleteObject(int objIdx) {
  }

  @Override
  protected void handleSortOrderChange() {
  }

  @Override
  public void updateObject(Object object) {
  }

}
